<template>
  <div class="activity">
    <div class="top_btn">
      <Button type="primary" @click="addBtn" v-if="unlocking('0215010100')">新建活动</Button>
    </div>

    <dt-grid ref="table" :page="page" :onFetch="onFetch" />

    <add-activity ref="addActivity"></add-activity>

    <prize-publish ref="releaseModel"></prize-publish>
  </div>
</template>

<script>
  import addActivity from './components/addActivity.vue'
  import columnOpt from './opt/column.js'
  import activityMgr from '@/biz/activity/activity'
  import prizePublish from './components/prizePublish.vue'

  export default {
    components: {
      addActivity,
      prizePublish
    },
    data() {
      return {
        page: {
          total: 0
        }
      }
    },

    mounted() {
      this.$refs.table.init(this, new columnOpt(this))
      this.$refs.table.fetch()
    },

    methods: {
      onFetch(info) {
        return activityMgr.basicsList(info).then((res) => {
          console.log('表格数据', res)
          this.page.total = res.total
          return res.list
        })
      },
      addBtn() {
        this.$refs.addActivity.show()
      },
      checkFun(val) {
        let dataVal = {
          acId: val.acId,
          name: val.name,
          status: val.status,
          btnFlag: 'flag'
        }
        this.$refs.releaseModel.show(dataVal)
      },
      editFun(row) {
        this.$router.push({
          path: '/marketing/activityDetail',
          query: {
            // ...{ companyId: row.companyId, acId: row.acId }
            acId: row.acId
          }
        })
      },
      delActivity(row) {
        this.$Modal.confirm({
          title: '删除',
          content: `是否删除该未发布的活动？`,
          okText: '确认',
          closable: true,
          onOk: () => {
            activityMgr.endBasics({ acId: row.acId, type: 'del' }).then((res) => {
              this.$Message.success('删除成功')
              this.$refs.table.fetch()
            })
          }
        })
      },
      copyActivity(row) {
        console.log('当前行数据', row)
        this.$refs.addActivity.show(row)
      },
      closeActivity(row) {
        this.$Modal.confirm({
          title: '强制结束',
          content: `是否强制结束该活动？强制结束后，该活动不可再度启用`,
          okText: '确认',
          closable: true,
          onOk: () => {
            activityMgr.endBasics({ acId: row.acId, type: 'end' }).then((res) => {
              this.$Message.success('该活动已结束')
              this.$refs.table.fetch()
            })
          }
        })
      },
      getActivityData(row) {
        console.log('当前行数据', row)
        this.$router.push({
          path: '/marketing/activityData',
          query: {
            acId: row.acId
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .activity {
    padding: 24px;
  }
</style>
